<template>
  <div class="contain">
    <div>
      <!-- 头部面包屑 -->
      <el-breadcrumb separator="|" class="headerTop">
          <el-breadcrumb-item><a href="/">首页</a></el-breadcrumb-item>
        <el-breadcrumb-item v-if="ishidden"
          ><a href="/login">您好,请登录</a></el-breadcrumb-item
        >
        <div v-else>
          <el-breadcrumb-item
            ><el-dropdown>
              <span class="el-dropdown-link">
                我的咸鱼<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item @click.native="joinUserCard">个人名片</el-dropdown-item>
                <el-dropdown-item @click.native="joinAddressCard">收货地址</el-dropdown-item>
                <el-dropdown-item @click.native="logout">注销</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-breadcrumb-item>
          <el-breadcrumb-item><a href="/PayGood">我的订单</a></el-breadcrumb-item>
        </div>
      </el-breadcrumb>
    </div>

    <!-- 中间 -->
    <div class="zhongjian">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
import common from "../util/common";
export default {
  // 设置背景颜色
  // beforeCreate() {
  //   document.querySelector("body").setAttribute("style", "background:#f4f4f4;");
  // },
  //  beforeDestroy () {
  //   document.querySelector('body').removeAttribute('style')
  // },
  data() {
    return {
      localhostPath: common.localhostPath,
      ishidden: true,
    };
  },
  methods: {
    isLogin() {
      var name = localStorage.getItem("realname");
      if (name != null) {
        this.ishidden = false;
      } else {
        this.ishidden = true;
      }
    },
    logout() {
      this.$confirm("此操作将退出主页面, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          localStorage.clear();
          location.reload();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消注销",
          });
        });
    },
    joinUserCard(){
      this.$router.push('/userInfo')
    },
    joinAddressCard(){
      this.$router.push('/AddressInfo')
    },
  },
  mounted() {
    this.isLogin();
  },
};
</script>

<style scoped>
/* 头部面包屑 */
.headerTop {
  display: flex;
  justify-content: flex-end;
  /* background-color: #e3e4e5; */
  height: 40px;
  line-height: 40px;
  margin: auto;
  padding-right: 100px;
}

li {
  list-style: none;
}
a {
  text-decoration: none;
  font-weight: 300 !important;
}
a:hover {
  color: #a1c323 !important;
}
.contain {
  padding: 0;
  margin: 0;
  margin-top: 0px !important;
}
.zhongjian {
  z-index: 1;
}
</style>